home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_03_01 / 3n01064a < prev    next >
Text File  |  1991-11-22  |  2KB  |  63 lines

  1. #include <stdlib.h>
  2. #include <limits.h>
  3. #include <string.h>
  4.  
  5. #include <windows.h>
  6.  
  7. #include "extstr.h"
  8.  
  9. char    **StringPointers;
  10.  
  11. int LoadExternalStrings_(HANDLE ResourceFile);
  12.  
  13. int LoadExternalStrings(HANDLE ResourceFile)
  14.     {
  15.     char    Message[256];
  16.  
  17.     if(!LoadExternalStrings_(ResourceFile))
  18.         {
  19.         if(!LoadString(ResourceFile, 0, Message, 255))
  20.             strcpy(Message, "Can't load language strings!");
  21.         MessageBox(NULL, Message, NULL, MB_ICONSTOP);
  22.         return 0;
  23.         }
  24.     else
  25.         return 1;
  26.     }
  27.  
  28. int LoadExternalStrings_(HANDLE ResourceFile)
  29.     {
  30.     char    *StringBuffer;
  31.     size_t  Offset, Length, SpaceLeft, BufferSize;
  32.     char    *LoadPoint;
  33.  
  34.     StringPointers  = (char **)malloc(
  35.             sizeof(char*)*(1+WINEXT_LINES));
  36.     BufferSize      = WINEXT_CHARS;
  37.     StringBuffer    = (char *)malloc(
  38.             sizeof(char)*BufferSize);
  39.     LoadPoint   = StringBuffer;
  40.     SpaceLeft   = BufferSize-1;
  41.     for(Offset = 1; Offset < WINEXT_LINES; ++Offset)
  42.         {
  43.         if(SpaceLeft < 255)
  44.             {
  45.             if((UINT_MAX - 512) > BufferSize)
  46.                 {
  47.                 BufferSize  += 512;
  48.                 StringBuffer    = (char *)realloc(
  49.                             StringBuffer, BufferSize);
  50.                 if(StringBuffer == NULL)
  51.                     return 0;   /* FAILURE! */
  52.                 }
  53.             else
  54.                 return 0;   /* FAILURE! */
  55.  
  56.             }
  57.         Length = LoadString(ResourceFile, Offset, LoadPoint, SpaceLeft);
  58.         StringPointers[Offset]  = LoadPoint;
  59.         LoadPoint   += Length+1;
  60.         }
  61.     return 1;   /* SUCCESS! */
  62.     }
  63.